package xm.components.supportClasses
{
	import flash.display.Sprite;
	
	import xm.components.supportClasses.base.ComponentBase;
	
	
	/**
	 * <br> 클래스 설명 : 스킨을 입힐 수 있는 기본 컴포넌트</br>
	 * @author 김정환
	 */	
	public class SkinnableComponent extends ComponentBase
	{
		
		//-----------------------------------------------------------------------------------
		// public vars
		//-----------------------------------------------------------------------------------
		
		
		
		
		
		//-----------------------------------------------------------------------------------
		// protected / internal vars
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		// private vars
		//-----------------------------------------------------------------------------------
		
		private var _skinClass : Class;
		private var _skinLayer : Sprite;
		
		//-----------------------------------------------------------------------------------
		// public functions
		//-----------------------------------------------------------------------------------
		
		/**
		 * constructor 
		 */	
		public function SkinnableComponent()
		{
			super();
		}
		
		
		
		/**
		 * commitProperties
		 */		
		override public function commitProperties():void
		{
			super.commitProperties();
			
		}
		
		
		
		/**
		 * updateDisplayList
		 */		
		override public function updateDisplayList( enforce : Boolean = false ):void
		{
			super.updateDisplayList(enforce);
			
			if( _skinLayer )
			{
				_skinLayer.width = viewWidth;
				_skinLayer.height = viewHeight;
			}
		}
		
		
		
		//-----------------------------------------------------------------------------------
		// life cycle functions
		//-----------------------------------------------------------------------------------
		
		
		
		
		/**
		 * createChildren
		 */		
		override public function createChildren():void
		{
			super.createChildren();
			
			this.backgroundAlpha = 1;
			
		}
		
		
		
		/**
		 * createComplete
		 */		
		override public function creationComplete():void
		{
			super.creationComplete();
			
		}
		
		override public function add():void
		{
			super.add();
		}
		
		/**
		 * destroy
		 */		
		override public function destroy():void
		{
			super.destroy();
			
			if( _skinLayer )
			{
				if( contains( _skinLayer ) ) removeChild( _skinLayer );
				
				_skinLayer = null;
			}
			
			_skinClass = null;
		}
		
		//-----------------------------------------------------------------------------------
		// setter / getter
		//-----------------------------------------------------------------------------------
		
		
		/**
		 * @return 현재 적용된 스킨 클래스 반환.
		 */		
		public function get skinClass():Class
		{
			return _skinClass;
		}
		
		/**
		 * @param value Sprite ( MovieClip ) 클래스 명으로 삽입.
		 */		
		public function set skinClass(value:Class):void
		{
			_skinClass = value;
			
			if( _skinLayer && contains( _skinLayer ) )
			{
				removeChild( _skinLayer );
				_skinLayer = null;
			}
			
			_skinLayer = new _skinClass() as Sprite;
			addChildAt( _skinLayer, 0 );
		}
		
		
		
		//-----------------------------------------------------------------------------------
		// protected functions
		//-----------------------------------------------------------------------------------


		//-----------------------------------------------------------------------------------
		// internal functions
		//-----------------------------------------------------------------------------------
		
		
		
		
		//-----------------------------------------------------------------------------------
		// private functions
		//-----------------------------------------------------------------------------------
		
		
		
		//-----------------------------------------------------------------------------------
		// event handler
		//-----------------------------------------------------------------------------------
		
		
		
		
		
		
		
		
		
		
		
	}
}